﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

using HappyPlus.DataConfig;
using System;
using System.Reflection;

//public class DataConfigTagAttribute : Attribute
//{
//    public string ConfigName
//    {
//        get { return configName; }
//    }

//    public Type ConfigType
//    {
//        get { return configType; }
//    }

//    private string configName;
//    private Type configType;

//    public DataConfigTagAttribute(string configName, Type configType)
//    {
//        this.configName = configName;
//        this.configType = configType;
//    }
//}

//namespace HappyPlus.DataConfig
//{
//    public class DictData
//    {
//        private static Dictionary<int, MyExcelSheet> MyExcelSheetDict;
//        private static Dictionary<int, TestClassName> TestClassNameDict;

//        public static void Init()
//        {
//            var excelSheetData = Resources.Load<MyExcelSheetCollection>("DataAssets/MyExcelSheetCollection");
//            if (excelSheetData != null)
//            {
//                MyExcelSheetDict = excelSheetData.LoadDataToMap();
//            }

//            var testClassData = Resources.Load<TestClassNameCollection>("DataAssets/TestClassNameCollection");
//            if (testClassData != null)
//            {
//                TestClassNameDict = testClassData.LoadDataToMap();
//            }
//        }

//        public bool GetMyExcelSheet(int id, out MyExcelSheet configData)
//        {
//            return MyExcelSheetDict.TryGetValue(id, out configData);
//        }

//        public bool GetTestClassName(int id, out TestClassName configData)
//        {
//            return TestClassNameDict.TryGetValue(id, out configData);
//        }
//    }
//}

namespace HappyPlus.Test
{
    public class TestScript
    {
        public Dictionary<int, MyExcelSheet> MyExcelSheetDict;
        public Dictionary<int, TestClassName> TestClassNameDict;

        public void Init()
        {
            var excelSheetData = Resources.Load<MyExcelSheetCollection>("DataAssets/MyExcelSheetCollection");
            if (excelSheetData != null)
            {
                MyExcelSheetDict = excelSheetData.LoadDataToMap();
            }

            var testClassData = Resources.Load<TestClassNameCollection>("DataAssets/TestClassNameCollection");
            if (testClassData != null)
            {
                TestClassNameDict = testClassData.LoadDataToMap();
            }
        }

        public void TestMethod()
        {
            //Debug.Log("hello test");
            //var configData = Resources.Load<MyExcelSheetCollection>("DataAssets/MyExcelSheetCollection");
            //if (configData != null)
            //{
            //    var dataMap = configData.LoadDataToMap();
            //    if (dataMap != null)
            //    {
            //        foreach (var item in dataMap)
            //        {
            //            Debug.Log($"{item.Value.ID} - {item.Value.Name} - {item.Value.TelNo}");
            //        }
            //    }
            //}
            DataConfig.DictData.Init();
            if(DataConfig.DictData.GetMyExcelSheetData(1, out var data))
            {
                if(data != null)
                {
                    Debug.Log($"{data.ID} - {data.Name} - {data.TelNo}");
                }
            }
        }

        public void InitMethod()
        {
            //var configData = Resources.Load("DataAssets/MyExcelSheetCollection");
            //if (configData != null)
            //{
            //    var dataAsset = ScriptableObject.CreateInstance(configData.GetType());
            //    if (dataAsset != null)
            //    {
            //        Convert.ChangeType(dataAsset, typeof(MyExcelSheetCollection));
            //        var loadMethod = dataAsset.GetType().GetMethod("LoadDataToMap");
            //        if (loadMethod != null)
            //        {
            //            loadMethod.Invoke(dataAsset, new object[] { });
            //        }
            //    }
            //}
        }
    }
}
